import request from '@/utils/request'

export interface MenuVO {
  id: number
  name: string
  permission: string
  type: number
  sort: number
  parentId: number
  path: string
  icon: string
  component: string
  componentName?: string
  status: number
  visible: boolean
  keepAlive: boolean
  alwaysShow?: boolean
  createTime: Date
  openWith: string
  noClosable: boolean
  components: string
}

// 查询菜单（精简）列表
export const getSimpleMenusList = () => {
  return request({
    url: '/system/menu/simple-list',
    method: 'GET',
  })
}

// 查询菜单列表
export const getMenuList = (params?: any) => {
  return request({
    url: '/system/menu/list',
    method: 'GET',
    params,
  })
}

// 获取菜单详情
export const getMenu = (id: number) => {
  return request({
    url: `/system/menu/get?id=${id}`,
    method: 'GET',
  })
}
// 创建/更新菜单
export const saveOrUpdate = (data: MenuVO) => {
  return request({
    url: '/system/menu/saveOrUpdate',
    method: 'POST',
    data,
  })
}
// 新增菜单
export const createMenu = (data: MenuVO) => {
  return request({
    url: '/system/menu/create',
    method: 'POST',
    data,
  })
}

// 修改菜单
export const updateMenu = (data: MenuVO) => {
  return request({
    url: '/system/menu/update',
    method: 'PUT',
    data,
  })
}

// 删除菜单
export const deleteMenu = (id: number) => {
  return request({
    url: `/system/menu/delete?id=${id}`,
    method: 'DELETE',
  })
}

// 增加时根据父菜单查询子菜单最大的排序号
export const getMenuByParentIdNextSort = (id: number) => {
  return request({
    url: `/system/menu/getSort?parentId=${id}`,
    method: 'GET',
  })
}

// 拖拽
export const getMove = (data: any) => {
  return request({
    url: `/system/menu/getMove`,
    method: 'POST',
    data,
  })
}
